-- buffers
vim.keymap.set("n", "<Leader>w", vim.cmd.write, { desc = "Write buffer" })
vim.keymap.set("n", "<Leader>c", vim.cmd.bdelete, { desc = "Close buffer" })
vim.keymap.set("n", "]b", vim.cmd.bnext, { desc = "Next buffer" })
vim.keymap.set("n", "[b", vim.cmd.bprevious, { desc = "Previous buffer" })

-- scrolling
vim.keymap.set("n", "<C-d>", "<C-d>zz", { desc = "Scroll down half a page" })
vim.keymap.set("n", "<C-u>", "<C-u>zz", { desc = "Scroll up half a page" })

-- search
vim.keymap.set("n", "n", "nzz", { desc = "Next search result" })
vim.keymap.set("n", "N", "Nzz", { desc = "Previous search result" })
vim.keymap.set("n", "*", "*zz", { desc = "Search forward for word" })
vim.keymap.set("n", "#", "#zz", { desc = "Search backward for word" })

-- move line
vim.keymap.set("n", "<M-j>", "<Cmd>silent! move+1<CR>==", { desc = "Move line down" })
vim.keymap.set("n", "<M-k>", "<Cmd>silent! move-2<CR>==", { desc = "Move line up" })

-- move block
vim.keymap.set("x", "<M-j>", "<Esc><Cmd>silent! '<,'>move'>+1<CR>gv=gv", { desc = "Move block down" })
vim.keymap.set("x", "<M-k>", "<Esc><Cmd>silent! '<,'>move'<-2<CR>gv=gv", { desc = "Move block up" })

-- indent block
vim.keymap.set("x", "<", "<gv", { desc = "Indent block left" })
vim.keymap.set("x", ">", ">gv", { desc = "Indent block right" })

-- paste selection
vim.keymap.set("x", "p", "P", { desc = "Paste without yank" })

-- subsitute pattern
vim.keymap.set("n", "<Leader>r", ":%s/<C-r><C-w>//gc<Left><Left><Left>", { desc = "Search and replace" })
vim.keymap.set("x", "<Leader>r", "y:%s/<C-r>0//gc<Left><Left><Left>", { desc = "Search and replace" })

-- file explorer
vim.keymap.set("n", "-", vim.cmd.Explore, { desc = "File explorer" })

-- terminal
vim.keymap.set("t", "<Esc>", [[<C-\><C-n>]], { desc = "Enter normal mode" })
